package cn.edu.lingnan.config;

import com.aliyun.ocr_api20210707.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class AliyunOcrConfig {

    @Value("${aliyun.key-id}")
    private String keyId;

    @Value("${aliyun.key-secret}")
    private String keySecret;

    @Value("${aliyun.endpoint}")
    private String endpoint;

    @Bean
    public Client ocrClient() {
        try {
            return new Client(new Config()
                    .setAccessKeyId(keyId)
                    .setAccessKeySecret(keySecret)
                    .setEndpoint(endpoint));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}